package xyz.ddlnt.management.mg.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.model.dto.CategoryDTO;
import xyz.ddlnt.model.entity.Category;
import xyz.ddlnt.servicemgclient.client.CategoryFeignClient;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/1 21:54
 */
@Slf4j
@Tag(name = "分类管理接口")
@RestController
@RequestMapping(("/category"))
public class CategoryController {

    @Resource
    private CategoryFeignClient categoryFeignClient;

    @Operation(summary = "获取分类")
    @GetMapping("getCategory")
    public Result<List<Category>> getCategory() {
        return categoryFeignClient.getAllCategory();
    }

    @Operation(summary = "获取所有分类名称")
    @GetMapping("getAllName")
    public Result<List<CategoryDTO>> getAllCategoryName() {
        return categoryFeignClient.getAllCategoryName();
    }

    @Operation(summary = "添加分类")
    @PostMapping("/addCategory")
    public Result<Category> addCategory(@RequestBody Map<String, String> map) {
        return categoryFeignClient.addCategory(map.get("categoryName"));
    }

    @Operation(summary = "删除分类")
    @DeleteMapping("/deleteCategory/{id}")
    public Result<String> deleteCategory(@PathVariable Long id) {
        return categoryFeignClient.deleteCategory(id);
    }

    @Operation(summary = "更新分类")
    @PutMapping("/updateCategory")
    public Result<LocalDateTime> updateCategory(@RequestBody CategoryDTO categoryDTO) {
        return categoryFeignClient.updateCategory(categoryDTO);
    }
}